package licslan.hwl.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import licslan.hwl.dubbo.redis.RedisService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/test")
public class TestRedis {

    @Reference(version = "5.0.0")
    private RedisService redisService;

   /* @Reference(version = "1.0.0")
    private DemoServiceXXX demoService;*/

    @RequestMapping(value="/index")
    public String index(){
        return "hello world";
    }

    /**
     * 向redis存储值
     * @return
     * @throws Exception
     */
    @RequestMapping("/set")
    public String set() throws Exception{
        String key ="licslan";
        String value ="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        redisService.set(key, value);
        return "success";
    }

    /**
     * 获取redis中的值
     * @param key
     * @return
     */
    @RequestMapping("/get")
    public String get(String key){
        try {
            return redisService.get(key);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 获取数据库中的用户
     * @param id
     * @return
     */
   /* @RequestMapping("/getUser/{id}")
    public String get(@PathVariable("id")int id){
        System.out.println("-----------------test");
        try {
            List<TestUser> user= demoService.selectList();
            return JsonUtil.getJsonString(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }*/


}